import datetime
from typing import List, Optional

from pydantic import BaseModel


# test
class RuleBase(BaseModel):
    title: str
    description: Optional[str] = None


class RuleCreate(RuleBase):
    pass


class Rule(RuleBase):
    target: str
    max: str
    min: str

    class Config:
        orm_mode = True


# version 表的实体类
class VersionBase(BaseModel):
    title: str
    description: Optional[str] = None

    bid: str
    # platform: str
    # device_id_list: List
    md5: str
    download_url: str
    max_os_api: int
    min_os_api: int
    cpu_arch: str
    channel: str


class VersionCreate(VersionBase):
    # versions are strs when created, but stored as int in the database
    version: str
    max_version: str
    min_version: str


class Version(RuleBase):
    id: int
    bid: str
    version: str
    md5: str
    download_url: str
    max_os_api: int
    min_os_api: int
    max_version: int
    min_version: int
    cpu_arch: str
    channel: str
    platform: str
    pop_count: int
    install_count: int
    aid: int
    create_time: datetime.datetime
    delete_time: str
    is_delete: bool
    is_release: bool

    class Config:
        orm_mode = True


# version_message 表的实体类
class VersionMessageBase(BaseModel):
    title: str
    description: Optional[str] = None


class VersionMessageCreate(VersionMessageBase):
    pass


class VersionMessage(VersionMessageBase):
    id: int
    bid: str
    user_bid: str
    version: int
    version_bid: str
    operation: int
    content: str
    create_time: datetime.datetime

    class Config:
        orm_mode = True
